<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index13-Class类</title>
</head>
<body>
  <script type="text/javascript">

    //  定义一个Person类
    class Person {
      // 定义构造函数
      constructor(name, age) {
        this.name = name;
        this.age = age;
      }
      // 定义普通的方法
      getInfo(){
        return `姓名:${this.name},年龄:${this.age}`;
      }
    }
    // 创建对象
    let person = new Person("jack", 10);
    console.log(person);
    console.log(person.getInfo());

    // 子类继承父类
    class BlackPerson extends Person {
      constructor(name, age, height) {
        super(name, age);
        this.height= height;
      }
      // 重写父类中getInfo方法
      getInfo(){
        // return `姓名:${this.name},年龄:${this.age},身高:${this.height}`;
        // super.getInfo():调用父类的getInfo方法
        return super.getInfo() + `,身高:${this.height}`;
      }
    }
    // 创建子类对象
    let blackPerson = new BlackPerson("小黑", 20, 180);
    console.log(blackPerson);
    console.log(blackPerson.getInfo());
  </script>
</body>
</html>